package xiaodou.core.WeiboData
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	import spark.formatters.DateTimeFormatter;
	
	import xiaodou.core.WeiboData.WeiboCommentsData;
	import xiaodou.core.WeiboData.events.WeiboDataEvent;
	import xiaodou.core.WeiboData.events.WeiboEvent;
	
	public class WeiboCommentsInfo extends EventDispatcher
	{
		public var _CommentsToMeData:WeiboCommentsData = new WeiboCommentsData();      //我收到的评论
		public var _CommentsMentionMeData:WeiboCommentsData = new WeiboCommentsData(); //@我的评论
		public var _CommentsSendByMeData:WeiboCommentsData = new WeiboCommentsData();  //我发出的评论
		
		
		public function WeiboCommentsInfo(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public function RemoveAllData():void
		{
			_CommentsToMeData.RemoveAllData();
			_CommentsMentionMeData.RemoveAllData();
			_CommentsSendByMeData.RemoveAllData();
		}
		
		/**
		 * 获得一周内我收到的评论内容
		 * @param page 第几页,从0页开始
		 * @param commentsPerPage 每页有多少条评论
		 * @return 
		 * 
		 */		
		public function GetOneWeekCommentsToMe(page:int, commentsPerPage:int = 15):Array
		{
			var today:Date = new Date();
			var AWeekAgo:Date = new Date(today.time - WeiboFansInfo.millisecondsPerDay*7);
			var ary:Array = _CommentsToMeData.GetCommentsByDate(AWeekAgo, today);
			
			if(commentsPerPage > ary.length)
				return ary;
			
			var nMaxIndex:int = ((page+1)*commentsPerPage-1 > ary.length) ? (ary.length-1) : (page+1)*commentsPerPage-1;
			return ary.slice(page*commentsPerPage, nMaxIndex);
			
		}
		
		public function OneWeekCommentsToMeReady():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.GET_ONEWEEK_COMMENTS_TO_ME_SUCCESS);
			dispatchEvent(Evt);
		}
		
		/**
		 * 获得一周内@我的评论内容
		 * @param page 第几页
		 * @param commentsPerPage 每页有多少条评论
		 * @return 
		 * 
		 */		
		public function GetOneWeekCommentsMentionMe(page:int, commentsPerPage:int):Array
		{
			var today:Date = new Date();
			var AWeekAgo:Date = new Date(today.time - WeiboFansInfo.millisecondsPerDay*7);
			var ary:Array = _CommentsMentionMeData .GetCommentsByDate(AWeekAgo, today);
			
			if(commentsPerPage > ary.length)
				return ary;
			
			var nMaxIndex:int = ((page+1)*commentsPerPage-1 > ary.length) ? (ary.length-1) : (page+1)*commentsPerPage-1;
			return ary.slice(page*commentsPerPage, nMaxIndex);
		}
		
		public function OneWeekCommentsMentionMeReady():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.GET_ONEWEEK_COMMENTS_MENTION_ME_SUCCESS);
			dispatchEvent(Evt);
		}
		
		/**
		 * 获得一周内我发出的的评论内容
		 * @param page 第几页
		 * @param commentsPerPage 每页有多少条评论
		 * @return 
		 * 
		 */		
		public function GetOneWeekCommentsSendByMe(page:int, commentsPerPage:int):Array
		{
			var today:Date = new Date();
			var AWeekAgo:Date = new Date(today.time - WeiboFansInfo.millisecondsPerDay*7);
			var ary:Array = _CommentsSendByMeData .GetCommentsByDate(AWeekAgo, today);
			
			if(commentsPerPage > ary.length)
				return ary;
			
			var nMaxIndex:int = ((page+1)*commentsPerPage-1 > ary.length) ? (ary.length-1) : (page+1)*commentsPerPage-1;
			return ary.slice(page*commentsPerPage, nMaxIndex);
		}
		
		public function OneWeekCommentsSendByMeReady():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.GET_ONEWEEK_COMMENTS_SENDBY_ME_SUCCESS);
			dispatchEvent(Evt);
		}

		public function OneDayCommentsCountsReady():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.GET_ONEDAY_COMMENTS_COUNTS_SUCCESS);
			dispatchEvent(Evt);
		}
		
		public function OneDayCommentsCountsError():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.GET_ONEDAY_STATUS_COUNTS_ERROR);
			dispatchEvent(Evt);
		}
		
		public function UpdateCommentSuccess():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.UPDATE_SUCCESS);
			dispatchEvent(Evt);
		}
		
		public function UpdateCommentFailed():void
		{
			var Evt:WeiboEvent = new WeiboEvent(WeiboDataEvent.UPDATE_ERROR);
			dispatchEvent(Evt);
		}

	}
}